<!doctype html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Java对象序列化深度解析</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        
        .card-hover {
            transition: all 0.3s ease;
        }
        
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 40px rgba(0,0,0,0.1);
        }
        
        .text-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
        }
        
        .drop-cap {
            float: left;
            font-size: 4rem;
            line-height: 1;
            font-weight: 700;
            margin-right: 0.5rem;
            margin-top: 0.2rem;
            color: #667eea;
            font-family: 'Noto Serif SC', serif;
        }
        
        .section-divider {
            height: 2px;
            background: linear-gradient(to right, transparent, #667eea, transparent);
            margin: 3rem 0;
        }
        
        .mermaid {
            display: flex;
            justify-content: center;
            margin: 2rem 0;
        }
        
        .icon-box {
            width: 60px;
            height: 60px;
            display: flex;
            align-items: center;
            justify-content: center;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border-radius: 15px;
            color: white;
            font-size: 24px;
            margin-bottom: 1rem;
        }
        
        .number-circle {
            width: 40px;
            height: 40px;
            border-radius: 50%;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            display: flex;
            align-items: center;
            justify-content: center;
            font-weight: bold;
            margin-right: 1rem;
            flex-shrink: 0;
        }
        
        .highlight-box {
            background: linear-gradient(135deg, #f5f7fa 0%, #e9ecef 100%);
            border-left: 4px solid #667eea;
            padding: 1.5rem;
            margin: 2rem 0;
            border-radius: 0 10px 10px 0;
        }
        
        @keyframes fadeInUp {
            from {
                opacity: 0;
                transform: translateY(30px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }
        
        .animate-fadeInUp {
            animation: fadeInUp 0.8s ease-out;
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20">
        <div class="container mx-auto px-6 text-center">
            <h1 class="text-5xl md:text-6xl font-bold mb-6 animate-fadeInUp">
                Java对象序列化深度解析
            </h1>
            <p class="text-xl md:text-2xl mb-8 opacity-90 animate-fadeInUp" style="animation-delay: 0.2s;">
                探索对象持久化的奥秘，掌握数据传输的艺术
            </p>
            <div class="flex justify-center space-x-8 animate-fadeInUp" style="animation-delay: 0.4s;">
                <div class="text-center">
                    <i class="fas fa-database text-4xl mb-2"></i>
                    <p class="text-sm">持久化存储</p>
                </div>
                <div class="text-center">
                    <i class="fas fa-network-wired text-4xl mb-2"></i>
                    <p class="text-sm">网络传输</p>
                </div>
                <div class="text-center">
                    <i class="fas fa-shield-alt text-4xl mb-2"></i>
                    <p class="text-sm">安全防护</p>
                </div>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <main class="container mx-auto px-6 py-12">
        <!-- 引言卡片 -->
        <div class="bg-white rounded-2xl shadow-xl p-8 mb-12 card-hover">
            <div class="flex items-start">
                <div class="icon-box mr-6">
                    <i class="fas fa-question-circle"></i>
                </div>
                <div class="flex-1">
                    <h2 class="text-3xl font-bold mb-4 text-gray-800">为什么对象需要序列化？</h2>
                    <p class="text-lg text-gray-600 leading-relaxed">
                        <span class="drop-cap">想</span>象一下，你要把一个精美的玩具模型寄给远方的朋友。如果直接装箱邮寄，模型可能会在运输中损坏。明智的做法是将模型拆解、妥善包装，确保每个部件都能安全送达。这就是序列化的本质——将复杂的对象转换为可传输、可存储的字节流。
                    </p>
                </div>
            </div>
        </div>

        <!-- 核心概念可视化 -->
        <div class="bg-white rounded-2xl shadow-xl p-8 mb-12">
            <h2 class="text-3xl font-bold mb-6 text-center text-gradient">序列化流程图解</h2>
            <div class="mermaid">
                graph LR
                    A[Java对象] -->|序列化| B[字节流]
                    B -->|存储| C[文件系统]
                    B -->|传输| D[网络]
                    B -->|缓存| E[内存]
                    C -->|反序列化| F[还原对象]
                    D -->|反序列化| F
                    E -->|反序列化| F
                    
                    style A fill:#667eea,stroke:#fff,stroke-width:2px,color:#fff
                    style B fill:#764ba2,stroke:#fff,stroke-width:2px,color:#fff
                    style F fill:#667eea,stroke:#fff,stroke-width:2px,color:#fff
            </div>
        </div>

        <!-- 工作原理 -->
        <section class="mb-12">
            <h2 class="text-3xl font-bold mb-8 text-center">
                <i class="fas fa-cogs text-gradient mr-3"></i>
                序列化工作原理
            </h2>
            <div class="grid md:grid-cols-2 gap-6">
                <div class="bg-white rounded-xl shadow-lg p-6 card-hover">
                    <div class="flex items-start">
                        <div class="number-circle">1</div>
                        <div>
                            <h3 class="text-xl font-semibold mb-2">标记可序列化类</h3>
                            <p class="text-gray-600">实现 Serializable 接口，标识类的对象可被序列化。这是一个标记接口，告诉JVM该类支持序列化操作。</p>
                        </div>
                    </div>
                </div>
                
                <div class="bg-white rounded-xl shadow-lg p-6 card-hover">
                    <div class="flex items-start">
                        <div class="number-circle">2</div>
                        <div>
                            <h3 class="text-xl font-semibold mb-2">保存对象状态</h3>
                            <p class="text-gray-600">ObjectOutputStream 遍历对象的所有字段，将基本类型、对象引用等值写入字节流。</p>
                        </div>
                    </div>
                </div>
                
                <div class="bg-white rounded-xl shadow-lg p-6 card-hover">
                    <div class="flex items-start">
                        <div class="number-circle">3</div>
                        <div>
                            <h3 class="text-xl font-semibold mb-2">递归序列化</h3>
                            <p class="text-gray-600">如果对象包含其他对象引用，这些对象也会被递归序列化，确保整个对象图完整保存。</p>
                        </div>
                    </div>
                </div>
                
                <div class="bg-white rounded-xl shadow-lg p-6 card-hover">
                    <div class="flex items-start">
                        <div class="number-circle">4</div>
                        <div>
                            <h3 class="text-xl font-semibold mb-2">特殊处理</h3>
                            <p class="text-gray-600">静态字段和 transient 字段不会被序列化，循环引用会进行特殊处理避免无限递归。</p>
                        </div>
                    </div>
                </div>
                
                <div class="bg-white rounded-xl shadow-lg p-6 card-hover">
                    <div class="flex items-start">
                        <div class="number-circle">5</div>
                        <div>
                            <h3 class="text-xl font-semibold mb-2">保存类描述符</h3>
                            <p class="text-gray-600">除了对象状态，还会保存类名、版本号等元信息，确保反序列化时能正确恢复对象结构。</p>
                        </div>
                    </div>
                </div>
                
                <div class="bg-white rounded-xl shadow-lg p-6 card-hover">
                    <div class="flex items-start">
                        <div class="number-circle">6</div>
                        <div>
                            <h3 class="text-xl font-semibold mb-2">输出字节流</h3>
                            <p class="text-gray-600">将完整的字节流写入目标输出流，可以是文件、网络连接或内存缓冲区。</p>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <div class="section-divider"></div>

        <!-- Serializable 接口详解 -->
        <section class="mb-12">
            <div class="bg-gradient-to-r from-purple-50 to-indigo-50 rounded-2xl p-8">
                <h2 class="text-3xl font-bold mb-6 text-center">
                    <i class="fas fa-key text-gradient mr-3"></i>
                    Serializable 接口的重要性
                </h2>
                <div class="grid md:grid-cols-2 gap-8">
                    <div>
                        <h3 class="text-xl font-semibold mb-4 text-purple-800">
                            <i class="fas fa-tag mr-2"></i>标记接口的作用
                        </h3>
                        <p class="text-gray-700 leading-relaxed mb-4">
                            Serializable 是一个标记接口，不包含任何方法。它的存在告诉编译器和JVM，这个类的实例可以被序列化。这种设计模式简洁而优雅，通过接口继承来表达类的能力。
                        </p>
                        <div class="highlight-box">
                            <p class="text-sm text-gray-600">
                                <i class="fas fa-info-circle mr-2 text-purple-600"></i>
                                如果尝试序列化未实现 Serializable 接口的对象，将抛出 NotSerializableException 异常。
                            </p>
                        </div>
                    </div>
                    <div>
                        <h3 class="text-xl font-semibold mb-4 text-purple-800">
                            <i class="fas fa-code-branch mr-2"></i>版本控制机制
                        </h3>
                        <p class="text-gray-700 leading-relaxed mb-4">
                            serialVersionUID 字段用于标识序列化类的版本。当类结构发生变化时，通过版本号可以检测兼容性，确保序列化和反序列化的一致性。
                        </p>
                        <div class="bg-gray-800 text-white p-4 rounded-lg">
                            <code class="text-sm">
                                private static final long serialVersionUID = 1L;
                            </code>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- 应用场景 -->
        <section class="mb-12">
            <h2 class="text-3xl font-bold mb-8 text-center">
                <i class="fas fa-rocket text-gradient mr-3"></i>
                序列化的实际应用
            </h2>
            <div class="grid md:grid-cols-3 gap-6">
                <div class="bg-white rounded-xl shadow-lg overflow-hidden card-hover">
                    <div class="hero-gradient p-6 text-white">
                        <i class="fas fa-save text-4xl mb-3"></i>
                        <h3 class="text-xl font-bold">持久化存储</h3>
                    </div>
                    <div class="p-6">
                        <p class="text-gray-600">将